package com.dhms.vostok1

import android.app.Application
import android.content.Context
import com.alibaba.android.arouter.launcher.ARouter
import com.dhms.lib.app.LibApplication
import com.dhms.vostok1.data.fault.FaultLevelListData
import com.dhms.vostok1.database.Vostok1Database
import io.flutter.embedding.engine.FlutterEngineGroup

class MainApplication : LibApplication() {

    val database: Vostok1Database by lazy { Vostok1Database.getDatabase(this) }

    var faultLevel: FaultLevelListData? = null

    lateinit var engines: FlutterEngineGroup

    override fun onCreate() {
        super.onCreate()
        INSTANCE = this
        engines = FlutterEngineGroup(this)
        initSDK(INSTANCE)
    }

    private fun initSDK(instance: Application) {
        if (BuildConfig.DEBUG) {// 这两行必须写在init之前，否则这些配置在init过程中将无效
            ARouter.openLog()   // 打印日志
            ARouter.openDebug() // 开启调试模式(如果在InstantRun模式下运行，必须开启调试模式！线上版本需要关闭,否则有安全风险)
        }
        ARouter.init(instance) // 尽可能早，推荐在Application中初始化
    }

    companion object {
        private lateinit var INSTANCE: MainApplication

        fun getContext(): Context {
            return INSTANCE
        }

        fun getApplication():Application{
            return INSTANCE
        }
    }
}